//package com.note.config;
//
//import com.alibaba.fastjson.JSONObject;
//import freemarker.template.Configuration;
//import freemarker.template.Template;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.core.annotation.Order;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.PrintWriter;
//import java.util.Map;
//
///**
// * @author Xiongx
// * @version 1.0
// * @date 2021/5/1 0:13
// * @since JDK 1.8
// */
//@Aspect
//@Component
//@Order(6)
//public class ModelAopConfig {
//
//    @Pointcut("@annotation(com.note.config.ModelMapping)")
//    private void pointCut(){};
//
//    @Around("pointCut()")
//    public Object aroundJobConfig(ProceedingJoinPoint point) throws Throwable{
//        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest req=attributes.getRequest();
//        HttpServletResponse response=attributes.getResponse();
//        Object result=null;
//
//
//        result=point.proceed();
//        if(result==null){
//            return null;
//        }
//
//        Configuration configuration=SpringContextUtil.getBeanObj("note-freemarker");
//        Template template = configuration.getTemplate(result+".html");
//        // 准备输出， 使用模板的编码作为本页的charset
//        response.setContentType("text/html; charset=" + template.getEncoding());
//        //获取传入目标方法的参数
//        Object[] args = point.getArgs();
//        for (int i = 0; i < args.length; i++) {
//            if(args[i] instanceof Map){
//                try{
//                    PrintWriter out = response.getWriter();
//                    // 在模板中加入动态数据
//                    template.process(args[i], out);
//                }
//                catch(freemarker.template.TemplateException e){
//                    throw new ServletException("处理Template模版中出现错误", e);
//                }
//
//            }
//            System.out.println("第" + (i+1) + "个参数为:" + args[i]);
//        }
//        return result;
//    }
//
//}
